
#ifndef __CCE_MATERIAL_MATERIALMATERIALEDITORDIALOG_H__
#define __CCE_MATERIAL_MATERIALMATERIALEDITORDIALOG_H__

#include <qdialog.h>
#include <material/materialmanager.h>
#include <material/materialeditor.h>
#include <material/materialview.h>
#include <material/materialeditor/textureslot.h>
#include <ui_materialeditorwidget.h>


class cceMaterialBoolValueItem : public cceMaterialSimpleValueItem
{
	Q_OBJECT
private:
  bool    _checked;
  QString _name;
  bool    _active;

public:
  cceMaterialBoolValueItem (const QString& name);

  void SetChecked (bool checked);
  bool IsChecked () const { return _checked; }

  void mousePressEvent (QGraphicsSceneMouseEvent *event);
  void mouseReleaseEvent (QGraphicsSceneMouseEvent *event);

signals:
	void Changed ();
};

class cceMaterialColorValueItem : public cceMaterialSimpleValueItem
{
	Q_OBJECT
private:
  QColor    _color;

  bool      _active;

public:
  cceMaterialColorValueItem (const QString& name);

  void SetColor (const QColor &color);
  const QColor &GetColor () const { return _color; }

  void mousePressEvent(QGraphicsSceneMouseEvent *event);
  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);

signals:
	void Changed ();
};

class cceMaterialShininessValueItem : public cceMaterialSimpleValueItem
{
	Q_OBJECT
private:
  float _shininess;

public:
  cceMaterialShininessValueItem ();

  void SetShininess (float shininess);
  float GetShininess () const { return _shininess; }

signals:
	void Changed ();
};


class cceMaterialMaterialSpecTechniqueItem : public cceMaterialTechniqueItem
{
	Q_OBJECT
private:
  cceMaterialColorValueItem     *_colorAmbient;
  cceMaterialColorValueItem     *_colorDiffuse;
  cceMaterialColorValueItem     *_colorSpecular;
  cceMaterialShininessValueItem *_shininess;
  cceMaterialColorValueItem     *_colorEmission;
  cceMaterialBoolValueItem      *_writeDepth;
  cceMaterialBoolValueItem      *_testDepth;
  cceMaterialBoolValueItem      *_transparent;

public:
  cceMaterialMaterialSpecTechniqueItem ();

  cceMaterialColorValueItem* GetAmbient () { return _colorAmbient; }
  cceMaterialColorValueItem* GetDiffuse () { return _colorDiffuse; }
  cceMaterialColorValueItem* GetSpecular () { return _colorSpecular; }
  cceMaterialShininessValueItem* GetShininess () { return _shininess; }
  cceMaterialColorValueItem* GetEmission () { return _colorEmission; }
  cceMaterialBoolValueItem* GetWriteDepth () { return _writeDepth; }
  cceMaterialBoolValueItem* GetTestDepth () { return _testDepth; }
  cceMaterialBoolValueItem* GetTransparent () { return _transparent; }

signals:
	void Changed ();

};

class cceMaterialMaterialPrimaryItem;
class cceMaterialEffectSlotItem : public cceMaterialSlotItem
{
	Q_OBJECT
private:
  cceMaterialMaterialPrimaryItem  *_primary;

protected:
  void dragEnterEvent (QGraphicsSceneDragDropEvent* evt);
  void dropEvent (QGraphicsSceneDragDropEvent* evt);

public:
  cceMaterialEffectSlotItem (cceMaterialMaterialPrimaryItem  *primary);

};

class cceMaterialEffectValueItem : public cceMaterialValueItem
{
  Q_OBJECT
private:
  cceMaterialMaterialPrimaryItem  *_primary;
  cceMaterialEffect               *_effect;

protected:
  void dragEnterEvent (QGraphicsSceneDragDropEvent* evt);
  void dropEvent (QGraphicsSceneDragDropEvent* evt);

protected slots:
  void onEffectChanged ();
  virtual void RemoveValue ();
  void onShowEffect ();

public:
  cceMaterialEffectValueItem (cceMaterialMaterialPrimaryItem  *primary);

  void SetEffect (cceMaterialEffect*  effect);

signals:
  void ShowEditor (cceMaterialItem *item);
};

class cceMaterialTexturesItem;
class cceMaterialTextureItem : public QObject, public QGraphicsRectItem
{
  Q_OBJECT
private:
  QGraphicsSimpleTextItem     *_type;
  QGraphicsSimpleTextItem     *_name;

  QGraphicsRectItem           *_noTexture;
  QGraphicsPixmapItem         *_textureItem;

  cceMaterialTexture          *_texture;

  cceMaterialRemoveItem       *_remove;

  bool                        _active;
  unsigned                    _unit;
  cceMaterialTexturesItem     *_parent;
  cceMaterialView *GetView ();
	bool												_hot;

private slots:
  void remove ();
	void TextureRemoved ();
	void TextureChanged ();

protected:
  void dragEnterEvent (QGraphicsSceneDragDropEvent* evt);
  void dropEvent (QGraphicsSceneDragDropEvent* evt);
	void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
	void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
	void mousePressEvent (QGraphicsSceneMouseEvent *event);
	void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);

public:
  cceMaterialTextureItem (cceMaterialTexturesItem* parent, unsigned unit);

  void SetType (const QString& type);
	void ChangeTexture (cceMaterialTexture *texture);
  void SetTexture (cceMaterialTexture* texture);
  cceMaterialTexture *GetTexture () { return _texture; }

  void SetActive (bool active);
  bool IsActive () const { return _active; }

  void UpdateItems ();

signals:
	void Changed ();
	void ShowEditor (cceMaterialItem* item);
};

class cceMaterialTexturesItem : public cceMaterialBaseItem
{
	Q_OBJECT
private:
  QGraphicsRectItem                 *_background;

  cceMaterialTextureItem            *_textureItems[16];



public:
  cceMaterialTexturesItem (cceMaterialPass pass);

  void Clear ();
  void ClearActives ();
  void SetTextureNames (unsigned unit, const QSet<QString>& names);
  void SetTexture (unsigned unit, cceMaterialTexture* texture);
  cceMaterialTexture *GetTexture (unsigned unit);
  bool IsActive (unsigned unit) { return _textureItems[unit]->IsActive(); }



  virtual void ComputeSize ();
  virtual void UpdateLayout();
  void UpdateSize ();

signals:
	void Changed ();
	void ShowEditor (cceMaterialItem* item);
};

class cceMaterialTextureTechniqueItem : public cceMaterialTechniqueItem
{
	Q_OBJECT
private:

  cceMaterialTexturesItem       *_item;

public:
  cceMaterialTextureTechniqueItem (cceMaterialPass pass);

  void Clear ();
  void ClearActives ();
  void SetTextureNames (unsigned unit, const QSet<QString>& names);
  void SetTexture (unsigned unit, cceMaterialTexture* texture);
  cceMaterialTexture* GetTexture (unsigned unit);
  void UpdateItems ();

signals:
	void Changed ();
	void ShowEditor (cceMaterialItem* item);
};



class cceMaterialMaterialPrimaryItem : public cceMaterialPrimaryItem
{
  Q_OBJECT
private:
  cceMaterialMaterialSpecTechniqueItem    *_specItem;

  cceMaterialEffect                       *_effect;
  cceMaterialEffectSlotItem               *_effectSlot;
  cceMaterialEffectValueItem              *_effectValue;

  cceMaterialTextureTechniqueItem         *_texturesItems [Pass_COUNT];


public:
  cceMaterialMaterialPrimaryItem ();

	void ChangeEffect (cceMaterialEffect* effect);
  void SetEffect (cceMaterialEffect* effect);
  cceMaterialEffect* GetEffect ();

  void SetTexture (cceMaterialPass pass, unsigned unit, cceMaterialTexture* texture);
  cceMaterialTexture* GetTexture (cceMaterialPass pass, unsigned unit);


  cceMaterialMaterialSpecTechniqueItem* GetSpec () { return _specItem; }

signals:
	void Changed ();
  void ShowEditor (cceMaterialItem* item);
};





class cceMaterialMaterialEditorDialog : public cceMaterialEditorAbstract
{
  Q_OBJECT
private:
  cceMaterialMaterial               *_material;
//  cceMaterialMaterialPrimaryItem    *_primaryItem;

  Ui::MaterialMaterialEditorWidget  _gui;
//  cceMaterialView                   *_materialEditorView;


//	bool UpdateMaterialFromGUI ();
//  void UpdateGUIFromMaterial ();

//  bool MaterialChanged ();

private slots:
//	void Changed ();
//	void ForceClose ();
//	void on_lineEditName_textChanged (const QString& name);

public:
  cceMaterialMaterialEditorDialog(QWidget *parent);

  QString GetName () const;
  virtual bool Save ();

	void SetMaterial (cceMaterialMaterial* material);

public slots:
//	void Close ();
};

#endif /* ! __CCE_MATERIAL_MATERIALMATERIALEDITORDIALOG_H__ */

